<script>
export default {
  name: "studentHead",
  methods: {
    logout() {
      // 清除 localStorage 中的 token 和 userId
      localStorage.removeItem("token");
      localStorage.removeItem("userId");

      // 跳转到登录路由
      this.$router.push("/login");
      this.$message.success("已成功退出登录");
    }
  }
};
</script>

<template>
  <div class="container">
    <h2>学生宿舍管理系统</h2>
    <el-button type="danger" @click="logout" class="logout-button">退出登录</el-button>
  </div>
</template>

<style scoped>
.container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  border-bottom: 1px solid #ddd;
}

.logout-button {
  background-color: #ff4d4f;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s;
}

.logout-button:hover {
  background-color: #ff7875;
}
</style>
